//封装mysql方法
const mysql = require("mysql");
const pool = mysql.createPool({
    host: "127.0.0.1",
    user: "root",
    password: "root",
    database: "sephora",
    connectionLimit: 20,
    timeout: 30 * 1000//30秒内连接失败就报错
})
const exec = (sql, params) => {
    return new Promise((resolve, reject) => {
        pool.getConnection((err, conn) => {
            if (err) {
                console.log("连接失败");
                reject(err);
            }
            conn.query(sql, params, function (err, result) {
                if (err) {
                    console.log("获取失败");
                    reject(err);
                }
                resolve(result);
                conn.release();
            })
        })
    })
}
module.exports={
    exec
}